package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Objects;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysStudentCertificateMapper;
import com.ruoyi.system.domain.SysStudentCertificate;
import com.ruoyi.system.service.ISysStudentCertificateService;
import com.ruoyi.common.core.text.Convert;

/**
 * 培训证书Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@Service
public class SysStudentCertificateServiceImpl implements ISysStudentCertificateService 
{
    @Autowired
    private SysStudentCertificateMapper sysStudentCertificateMapper;

    /**
     * 查询培训证书
     * 
     * @param id 培训证书主键
     * @return 培训证书
     */
    @Override
    public SysStudentCertificate selectSysStudentCertificateById(Long id)
    {
        return sysStudentCertificateMapper.selectSysStudentCertificateById(id);
    }

    /**
     * 查询培训证书列表
     * 
     * @param sysStudentCertificate 培训证书
     * @return 培训证书
     */
    @Override
    public List<SysStudentCertificate> selectSysStudentCertificateList(SysStudentCertificate sysStudentCertificate)
    {
        List<SysRole> roles = ShiroUtils.getSysUser().getRoles();
        for (SysRole role : roles) {
            if (Objects.equals(role.getRoleKey(), "student")) {
                sysStudentCertificate.setUserId(ShiroUtils.getUserId());
            }
        }
        return sysStudentCertificateMapper.selectSysStudentCertificateList(sysStudentCertificate);
    }

    /**
     * 新增培训证书
     * 
     * @param sysStudentCertificate 培训证书
     * @return 结果
     */
    @Override
    public int insertSysStudentCertificate(SysStudentCertificate sysStudentCertificate)
    {
        sysStudentCertificate.setCreateTime(DateUtils.getNowDate());
        return sysStudentCertificateMapper.insertSysStudentCertificate(sysStudentCertificate);
    }

    /**
     * 修改培训证书
     * 
     * @param sysStudentCertificate 培训证书
     * @return 结果
     */
    @Override
    public int updateSysStudentCertificate(SysStudentCertificate sysStudentCertificate)
    {
        sysStudentCertificate.setUpdateTime(DateUtils.getNowDate());
        return sysStudentCertificateMapper.updateSysStudentCertificate(sysStudentCertificate);
    }

    /**
     * 批量删除培训证书
     * 
     * @param ids 需要删除的培训证书主键
     * @return 结果
     */
    @Override
    public int deleteSysStudentCertificateByIds(String ids)
    {
        return sysStudentCertificateMapper.deleteSysStudentCertificateByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除培训证书信息
     * 
     * @param id 培训证书主键
     * @return 结果
     */
    @Override
    public int deleteSysStudentCertificateById(Long id)
    {
        return sysStudentCertificateMapper.deleteSysStudentCertificateById(id);
    }
}
